package com.jp.lock;

import org.omg.Messaging.SYNC_WITH_TRANSPORT;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockTest {
    final  private  static  Lock lock = new ReentrantLock();

    public Lock getLock() {
        return lock;
    }

    public ReentrantLockTest() {
    }

    public static void main(String[] args) {

        new Thread(()->{
            lock.lock();
            try {
                TimeUnit.SECONDS.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            lock.unlock();
        },"Thread1").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        lock.lock();
        try {
            TimeUnit.SECONDS.sleep(1);
        }catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }
}
